import { login } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'
// import { Message } from 'element-ui'
export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    userInfo: {}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async login(context, payload) {
      const res = await login(payload)
      context.commit('setToken', res.data.token.token)
      context.commit('setUserInfo', res.data.user)
    }
  }
}
